package com.yj.springbootdynamic.config;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import javax.sql.DataSource;

public class DataSourceRouter extends AbstractRoutingDataSource {


    static final ThreadLocal<String> context = new ThreadLocal<>();

    @Override
    protected Object determineCurrentLookupKey() {
        return this.get();
    }


    public static String get(){
        return context.get();
    }

    public static void set(String dataSource){
        context.set(dataSource);
    }

    public void remove(){
        context.remove();
    }


}
